﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Security.Cryptography;

namespace Utility
{
	/// <summary>
	/// 哈希工具
	/// </summary>
	public class HashHelper
	{
		private HashHelper() { }

		// TODO: Hash provider name must match app.config
		private const string hashProvider = "PasswordHasher";

		public static string CreateHash(string plainText)
		{
			string hash = null;

			// TODO: Hash the plain text
			//hash = plainText;
			hash = Cryptographer.CreateHash(hashProvider, plainText);

			return hash;
		}

		public static bool CompareHash(string plainText, string hashedText)
		{
			bool compare = false;

			// TODO: Compare plain text with hash
			//compare = (plainText == hashedText);
			try
			{
				compare = Cryptographer.CompareHash(hashProvider, plainText, hashedText);
			}
			catch (Exception)
			{
				return false;
			}
			return compare;
		}
	}
}
